"""
Test Movies module 
"""

from django.test import TestCase
from RSM.my_friends.models import RSMUser, User
from RSM.my_friends.views import getUserNames
from RSM.my_movies.views import __updateUserMoviesList
from RSM.util import getRSMUser
from RSM.algorithm.search.makeCache import makeTestCache
getUserNames = getUserNames
updateUserMoviesList = __updateUserMoviesList
getRSMUser = getRSMUser
makeTestCache = makeTestCache


class MoviesTest(TestCase):
    added = False
    testCount = 1
    
    def setUp(self):
        print "\nMovies Test" + str(MoviesTest.testCount) + "\n"
        if (MoviesTest.added):
            return
        #adding a user to the system
        user = User.objects.create_user("Tomer", "t@t.com", "1234")
        user.save()
        RSMUser(user=user).save()
        #add some movies to the system
        makeTestCache()
                
    def tearDown(self):
        print "\nMovies Test" + str(MoviesTest.testCount) + "\n"
        MoviesTest.testCount += 1
        
        
    def test_1_addMovieToSeen(self):
        #adding movies to the list
        selectedList = ["Mov1","Mov2","Mov3"]
        username = "Tomer"
        movieType = "Seen"
        updateUserMoviesList(username,selectedList,movieType)
        print "Added 3 movies to seen"                
        currentUser = getRSMUser(username)
        #asserting addition 
        self.assertEquals(len(currentUser.seen.all()),3)
        print "There are 3 movies in seen"
        
    
    def test_2_addMovieToLikes(self):
        #adding movies to the list
        selectedList = ["Mov1","Mov2","Mov3"]
        username = "Tomer"
        movieType = "Seen"
        updateUserMoviesList(username,selectedList,movieType)
        print "Added 3 movies to seen"   
        selectedList = ["Mov3","Mov1"]
        username = "Tomer"
        movieType = "Likes"
        updateUserMoviesList(username,selectedList,movieType)
        print "Added 2 movies to likes"                   
        currentUser = getRSMUser(username)
        #asserting addition 
        self.assertEquals(len(currentUser.likes.all()),2)
        print "There are 2 movies in likes"   
        
    def test_3_addMovieToBlacklist(self):
        #adding movies to the list
        selectedList = ["Mov1","Mov2","Mov3"]
        username = "Tomer"
        movieType = "Seen"
        updateUserMoviesList(username,selectedList,movieType)
        print "Added 3 movies to seen"   
        selectedList = ["Mov2"]
        username = "Tomer"
        movieType = "Blacklist"
        updateUserMoviesList(username,selectedList,movieType)
        print "Added 1 movie to blacklist"                   
        currentUser = getRSMUser(username)
        #asserting addition 
        self.assertEquals(len(currentUser.blacklist.all()),1)
        print "There is 1 movie in blacklist"   
        
    def test_4_addUnSeenMovieToBlacklist(self):
        #adding movies to the list
        selectedList = ["Mov1","Mov2","Mov3"]
        username = "Tomer"
        movieType = "Seen"
        updateUserMoviesList(username,selectedList,movieType)
        print "Added 3 movies to seen"   
        selectedList = ["Mov5"]
        username = "Tomer"
        movieType = "Blacklist"
        updateUserMoviesList(username,selectedList,movieType)
        print "Added 1 movie to blacklist, movie not in seen"                   
        currentUser = getRSMUser(username)
        #asserting addition 
        self.assertEquals(len(currentUser.blacklist.all()),1)
        print "There is 1 movie in blacklist"       
        
    def test_5_addUnSeenMovieToLikes(self):
        #adding movies to the list
        selectedList = ["Mov1","Mov2","Mov3"]
        username = "Tomer"
        movieType = "Seen"
        updateUserMoviesList(username,selectedList,movieType)
        print "Added 3 movies to seen"   
        selectedList = ["Mov5"]
        username = "Tomer"
        movieType = "Likes"
        updateUserMoviesList(username,selectedList,movieType)
        print "Added 1 movie to likes"                   
        currentUser = getRSMUser(username)
        #asserting addition 
        self.assertEquals(len(currentUser.likes.all()),1)
        print "There is 1 movie in likes"   